

class TvDataBean {
  final List<String> urls;
  final String title;
  final Map<String, String>? header;
  const TvDataBean({this.header, required this.urls, required this.title});
  factory TvDataBean.fromJson(Map json) {
    return TvDataBean(
        urls: json['urls'], header: json['header'], title: json['title']);
  }

  static List<TvDataBean> fromJsons(List list) {
    if (list.isEmpty) return [];
    return List<TvDataBean>.from(list.map((e) => TvDataBean.fromJson(e)));
  }

  static List<TvDataBean> parseTxt(String content) {
    List<String> list = content.split("\n");
    List<TvDataBean> tvList = [];
    TvDataBean? bean;
    for (var item in list) {
      var arr = item.split(",");
      var title = arr[0];
      var url = arr[1];
      if (bean?.title == title) {
        bean!.urls.add(url);
      } else {
        bean = TvDataBean(title: title, urls: [url]);
        tvList.add(bean);
      }
    }
    return tvList;
  }
}

class TvLiveBean {
  final int version;
  final List<TvDataBean> list;
  const TvLiveBean({required this.version, required this.list});
  factory TvLiveBean.fromJson(Map json) {
    final List list = json['list'] ?? [];
    return TvLiveBean(
      version: json['version'],
      list: TvDataBean.fromJsons(list),
    );
  }
}
